using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Web;

namespace OurWedding1.Models
{ 
    public class GuestFunctionRepository : IGuestFunctionRepository
    {
        WeddingEntities context = new WeddingEntities();

        public IQueryable<GuestFunction> All
        {
            get { return context.GuestFunctions; }
        }

        public IQueryable<GuestFunction> AllIncluding(params Expression<Func<GuestFunction, object>>[] includeProperties)
        {
            IQueryable<GuestFunction> query = context.GuestFunctions;
            foreach (var includeProperty in includeProperties) {
                query = query.Include(includeProperty);
            }
            return query;
        }

        public GuestFunction Find(int id)
        {
            return context.GuestFunctions.Find(id);
        }

        public void InsertOrUpdate(GuestFunction guestfunction)
        {
            if (guestfunction.GuestFunctionId == default(int)) {
                // New entity
                context.GuestFunctions.Add(guestfunction);
            } else {
                // Existing entity
                context.Entry(guestfunction).State = EntityState.Modified;
            }
        }

        public void Delete(int id)
        {
            var guestfunction = context.GuestFunctions.Find(id);
            context.GuestFunctions.Remove(guestfunction);
        }

        public void Save()
        {
            context.SaveChanges();
        }

        public void Dispose() 
        {
            context.Dispose();
        }
    }

    public interface IGuestFunctionRepository : IDisposable
    {
        IQueryable<GuestFunction> All { get; }
        IQueryable<GuestFunction> AllIncluding(params Expression<Func<GuestFunction, object>>[] includeProperties);
        GuestFunction Find(int id);
        void InsertOrUpdate(GuestFunction guestfunction);
        void Delete(int id);
        void Save();
    }
}